//
//  HomePageCommentListViewController.m
//  ShowYork
//
//  Created by hxh on 2020/11/24.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "HomePageCommentListViewController.h"
#import "HomePageReplyListModel.h"
#import "HomePageCommentListCell.h"
#import "HomePageCommentItemModel.h"
@interface HomePageCommentListViewController ()<UITableViewDelegate,UITableViewDataSource,HomePageCommentListCellDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,assign)NSInteger pageIndex;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)UILabel *noDataLb;
@property (nonatomic,strong)NSNumber *postId;
@property (nonatomic,strong)NSNumber *lastId;
@property (nonatomic,strong)HomePageCommentItemModel *lastModel;
@property (nonatomic,assign)NSInteger total;
@end

@implementation HomePageCommentListViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}


- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (instancetype)initWithPostId:(NSNumber *)postId{
    if (self = [super init]) {
        self.postId = postId;
    }
    return self;
}

- (instancetype)initWithPostId:(NSNumber *)postId commentId:(NSNumber *)commentId{
    if (self = [super init]) {
        self.postId = postId;
        self.lastId = commentId;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.pageIndex = 1;
    self.isHideNavBar = YES;

    [self setUI];
    [self loadDataSource];
    [self registNote];
    
    // Do any additional setup after loading the view.
}
- (void)setUI{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.estimatedRowHeight = 100;
    self.tableView.estimatedSectionFooterHeight = .0f;
    self.tableView.estimatedSectionHeaderHeight = .0f;
    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.right.equalTo(self.view.mas_right);
        make.left.equalTo(self.view.mas_left);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    self.tableView.backgroundColor = [UIColor whiteColor];
    __weak typeof(self)weakSelf = self;
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        weakSelf.pageIndex++;
        [weakSelf loadDataSource];
    }];
    [footer setTitle:@"—— 没有更多了 ——" forState:MJRefreshStateNoMoreData];
    footer.stateLabel.font = font(10);
    footer.stateLabel.textColor = RGBA(153, 153, 153, 1);
    footer.hidden = YES;
    self.tableView.mj_footer = footer;
    
    self.noDataLb = [[UILabel alloc]init];
    self.noDataLb.text = @"还没有评论，快来抢沙发～";
    self.noDataLb.textColor = C153;
    self.noDataLb.font = font(12);
    [self.view addSubview:self.noDataLb];
    [self.noDataLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
    }];
    self.noDataLb.hidden = YES;
}
- (void)sendCommentMessage:(NSString *)commentText originalMessage:(NSString *)originalText userInfoList:(NSArray *)userInfoList{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"md5"] = [RPAppManager md5StrWithApi:AddPostComments];
    param[@"userId"] = [RPAppManager getCustomerId];
    param[@"postId"] = self.postId;
    param[@"commentText"] = commentText;
    param[@"original"] = originalText;
    if (userInfoList.count > 0) {
        NSMutableArray *arr = [NSMutableArray array];
        [userInfoList enumerateObjectsUsingBlock:^(UserInfoModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [arr addObject:obj.id];
        }];
        param[@"mentionIds"] = arr.mj_keyValues;
        
        [MobClick event:@"comment_detail_@_count"];
    }
    
    [[RPNetworkExtensionTool sharedTool]requestPOST:kGET_REQUEST_URL(AddPostComments) parames:param success:^(id responseObj) {
        
        [WHToast showImage:[UIImage imageNamed:@"toast_tag_success"] message:@"发送成功" duration:2 finishHandler:nil];
        
        self.noDataLb.hidden = YES;
        
        HomePageCommentItemModel *commentItem = [HomePageCommentItemModel mj_objectWithKeyValues:responseObj[RESPONSE]];
        
        [self.dataArray insertObject:commentItem atIndex:0];
        
        [self.tableView reloadData];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updateItemStatus" object:nil userInfo:@{@"data":self.postId,@"status":@1}];
        
        self.total++;
        if (self.updateCommentCount) {
            self.updateCommentCount(self.total);
        }
        CGFloat bottom = self.tableView.mj_insetB;
        if (self.dataArray.count == self.total) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
            if (self.tableView.mj_footer.cl_height == 44.0f) {
                self.tableView.mj_footer.cl_height = 138.0f;
                if (bottom == 44.0f || bottom == GK_SAVEAREA_BTM + 44.0f) {
                    self.tableView.mj_insetB = 138.0f;
                }

            }
        }else{
            [self.tableView.mj_footer resetNoMoreData];
            if (self.tableView.mj_footer.cl_height == 138.0f) {
                self.tableView.mj_footer.cl_height = 44.0f;
                if (bottom == 138.0f) {
                    self.tableView.mj_insetB = 44.0f;
                }
            }
        }
        
        [MobClick event:@"comment_detail_send"];
    
    } failure:^(NSError *error) {
        [WHToast showImage:[UIImage imageNamed:@"toast_tag_error"] message:error.userInfo[@"info"] duration:2 finishHandler:nil];
    }];
}
- (void)registNote{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateCommentItemStatus:) name:@"updateCommentItem" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllReply:) name:@"deleteAllCommentReply" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCommentLikeStatus:) name:@"updateCommentLikeStatus" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(removeCommentItem:) name:@"deleteCommentItem" object:nil];
    
}
- (void)removeCommentItem:(NSNotification *)note{
    __block NSInteger index = -1;
    HomePageCommentItemModel *model = note.userInfo[@"data"];
    [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.id isEqualToNumber:model.id]) {
            index = idx;
            *stop = YES;
        }
    }];
    if (index != -1) {
        [self.dataArray removeObjectAtIndex:index];

        if (self.dataArray.count == 0) {
            [self.tableView reloadData];
        }else{
            [self.tableView deleteRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
        }
    }
}
- (void)updateCommentLikeStatus:(NSNotification *)note{
    HomePageCommentItemModel *model = note.userInfo[@"data"];
    __block NSInteger index = -1;
    [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.id isEqualToNumber:model.id]) {
            index = idx;
            *stop = YES;
        }
    }];
    if (index != -1) {
        [self.tableView reloadRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
    }
    
}
- (void)updateCommentItemStatus:(NSNotification *)note{
    HomePageReplyListModel *itemModel = note.userInfo[@"data"];
    BOOL isAdd = [note.userInfo[@"status"] boolValue];
    __block NSInteger index = -1;
    [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.id isEqualToNumber:itemModel.commentId]) {
            index = idx;
            *stop = YES;
        }
    }];
    if (index != -1) {
        HomePageCommentItemModel *model = self.dataArray[index];
        HomePageReplyItemModel *newModel = [HomePageReplyItemModel new];
        newModel.userId = itemModel.userId;
        newModel.realName = itemModel.realName;
        newModel.imagePath = itemModel.imagePath;
        newModel.modifyTime = itemModel.modifyTime;
        newModel.deleted = itemModel.deleted;
        newModel.id = itemModel.id;
        newModel.likes = itemModel.likeNum;
        newModel.commentId = itemModel.commentId;
        newModel.createTime = itemModel.createTime;
        newModel.replyText = itemModel.replyText;
        newModel.replyMentionUsers = itemModel.mentionUserList;
        if (isAdd) {
            if (model.replyInCommentVM.replyNum.intValue == 0) {
                model.replyInCommentVM.replyNum = @1;
            }else{
                NSInteger num = model.replyInCommentVM.replyNum.intValue;
                num++;
                model.replyInCommentVM.replyNum = @(num);
            }
            model.replyInCommentVM.reply = newModel;
        }else{
            NSInteger num = model.replyInCommentVM.replyNum.intValue;
            num--;
            model.replyInCommentVM.replyNum = @(num);
            if (num == 1) {
                model.replyInCommentVM.reply = newModel;
            }
        }
        [self.tableView reloadRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
    }
    
}

- (void)removeAllReply:(NSNotification *)note{
    NSNumber *commentId = note.userInfo[@"data"];
    __block NSInteger index = -1;
    [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.id isEqualToNumber:commentId]) {
            index = idx;
            *stop = YES;
        }
    }];
    if (index != -1) {
        HomePageCommentItemModel *model = self.dataArray[index];
        model.replyInCommentVM.replyNum = @0;
        [self.tableView reloadRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}
- (void)sendReplyMessage:(NSString *)replyText originalMessage:(NSString *)originalText userInfoList:(NSArray *)userInfoList commentId:(NSNumber *)commentId{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"md5"] = [RPAppManager md5StrWithApi:AddCommentReply];
    param[@"userId"] = [RPAppManager getCustomerId];
    param[@"original"] = originalText;
    param[@"commentId"] = commentId;
    param[@"replyText"] = replyText;
    if (userInfoList.count > 0) {
        NSMutableArray *arr = [NSMutableArray array];
        [userInfoList enumerateObjectsUsingBlock:^(UserInfoModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [arr addObject:obj.id];
        }];
        param[@"mentionIds"] = arr.mj_keyValues;
        
        [MobClick event:@"comment_reply_@_count"];
    }
    [[RPNetworkExtensionTool sharedTool]requestPOST:kGET_REQUEST_URL(AddCommentReply) parames:param success:^(id responseObj) {
        [WHToast showImage:[UIImage imageNamed:@"toast_tag_success"] message:@"发送成功" duration:2 finishHandler:nil];
    
        self.noDataLb.hidden = YES;
        

        HomePageReplyListModel *itemModel = [HomePageReplyListModel mj_objectWithKeyValues:responseObj[RESPONSE]];
        __block NSInteger index = -1;
        [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj.id isEqualToNumber:commentId]) {
                index = idx;
                *stop = YES;
            }
        }];
        if (index != -1) {
            HomePageCommentItemModel *model = self.dataArray[index];
            HomePageReplyItemModel *newModel = [HomePageReplyItemModel new];
            newModel.userId = itemModel.userId;
            newModel.realName = itemModel.realName;
            newModel.imagePath = itemModel.imagePath;
            newModel.modifyTime = itemModel.modifyTime;
            newModel.deleted = itemModel.deleted;
            newModel.id = itemModel.id;
            newModel.likes = itemModel.likeNum;
            newModel.commentId = itemModel.commentId;
            newModel.createTime = itemModel.createTime;
            newModel.replyText = itemModel.replyText;
            newModel.replyMentionUsers = itemModel.mentionUserList;
            if (model.replyInCommentVM.replyNum.intValue == 0) {
                model.replyInCommentVM.replyNum = @1;
            }else{
                NSInteger num = model.replyInCommentVM.replyNum.intValue;
                num++;
                model.replyInCommentVM.replyNum = @(num);
            }
            model.replyInCommentVM.reply = newModel;
        }
    
        [self.tableView reloadRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];

        [MobClick event:@"comment_detail_send"];
        
    } failure:^(NSError *error) {
        [WHToast showImage:[UIImage imageNamed:@"toast_tag_error"] message:error.userInfo[@"info"] duration:2 finishHandler:nil];
    }];
}


- (void)loadDataSource{
    [self showDataLoadState];
    
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self loadMessageCommentList];
    });
    dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self loadTargetCommentSource];
    });
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        if (self.lastModel != nil) {
            self.lastModel.isDisplay = YES;
            __block NSInteger index = -1;
            [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj.id isEqualToNumber:self.lastModel.id] && !obj.isAdd) {
                    index = idx;
                    *stop = YES;
                }
            }];
            if (index != -1) {
                [self.dataArray removeObjectAtIndex:index];
            }
            if (!self.lastModel.isAdd) {
                self.lastId = @0;
                self.lastModel.isAdd = YES;
                [self.dataArray insertObject:self.lastModel atIndex:0];
            }
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                self.lastModel.isDisplay = 0;
                [self.tableView reloadRow:0 inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
            });
        }
        
        [self.tableView reloadData];
    
        if ([self.tableView.mj_footer isRefreshing]) {
            [self.tableView.mj_footer endRefreshing];
        }
        [self hideDataLoadLoadState];
    });
}
- (void)loadMessageCommentList{
    
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"md5"] = [RPAppManager md5StrWithApi:GetPostCommentList];
    param[@"postId"] = self.postId;
    param[@"pageIndex"] = @(self.pageIndex);
    param[@"pageSize"] = @10;
    param[@"userId"] = [RPAppManager getCustomerId];
    [[RPNetworkExtensionTool sharedTool] requestPOST:kGET_REQUEST_URL(GetPostCommentList) parames:param success:^(id responseObj) {
        if (self.pageIndex == 1) {
            self.dataArray = [HomePageCommentItemModel mj_objectArrayWithKeyValuesArray:responseObj[RESPONSE][LIST]];
        }else{
            [self.dataArray addObjectsFromArray:[HomePageCommentItemModel mj_objectArrayWithKeyValuesArray:responseObj[RESPONSE][LIST]]];
        }
        CGFloat bottom = self.tableView.mj_insetB;
        if ([responseObj[RESPONSE][LASTPAGE]boolValue]) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
            if (self.tableView.mj_footer.cl_height == 44.0f) {
                self.tableView.mj_footer.cl_height = 138.0f;
                if (bottom == 44.0f || bottom == GK_SAVEAREA_BTM + 44.0f) {
                    self.tableView.mj_insetB = 138.0f;
                }
            }
        }else{
            [self.tableView.mj_footer resetNoMoreData];
            if (self.tableView.mj_footer.cl_height == 138.0f) {
                self.tableView.mj_footer.cl_height = 44.0f;
                if (bottom == 138.0f) {
                    self.tableView.mj_insetB = 44.0f;
                }
            }
        }
        self.noDataLb.hidden = self.dataArray.count != 0;
        
        self.total = [responseObj[RESPONSE][TOTAL] intValue];
        
        if (self.updateCommentCount) {
            self.updateCommentCount(self.total);
        }
        
        dispatch_semaphore_signal(sema);
    } failure:^(id error) {
        self.pageIndex--;
        dispatch_semaphore_signal(sema);
    }];
    
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
- (void)loadTargetCommentSource{
    if (self.lastId.intValue == 0) {
        return;
    }
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"commentId"] = self.lastId;
    param[@"userId"] = [RPAppManager getCustomerId];
    param[@"md5"] = [RPAppManager md5StrWithApi:GetPostComment];
    [[RPNetworkExtensionTool sharedTool]requestPOST:kGET_REQUEST_URL(GetPostComment) parames:param success:^(id responseObj) {
        self.lastModel = [HomePageCommentItemModel mj_objectWithKeyValues:responseObj[RESPONSE]];
        self.lastModel.isDisplay = YES;
        dispatch_semaphore_signal(sema);
    } failure:^(NSError *error) {
        [WHToast showMessage:error.userInfo[@"info"] duration:2 finishHandler:nil];
        dispatch_semaphore_signal(sema);
    }];
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    self.tableView.mj_footer.hidden = self.dataArray.count == 0;
   
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HomePageCommentListCell *cell = [HomePageCommentListCell cellWithTableView:tableView];
    [cell setModel:self.dataArray[indexPath.row]];
    cell.delegate = self;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}

#pragma mark - HomePageCommentListCellDelegate
- (void)removePostCommentById:(NSNumber *)commentId{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"id"] = commentId;
    param[@"md5"] = [RPAppManager md5StrWithApi:DeletePostComments];
    [[RPNetworkExtensionTool sharedTool]requestPOST:kGET_REQUEST_URL(DeletePostComments) parames:param success:^(id responseObj) {
        __block NSInteger index = -1;
        [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj.id isEqualToNumber:commentId]) {
                index = idx;
                *stop = YES;
            }
        }];
        
        if (index != -1) {
            [self.dataArray removeObjectAtIndex:index];
            
            if (self.dataArray.count == 0) {
                [self.tableView reloadData];
            }else{
                [self.tableView deleteRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
            }
        }
        self.total--;
        if (self.updateCommentCount) {
            self.updateCommentCount(self.total);
        }
        
        CGFloat bottom = self.tableView.mj_insetB;
        if (self.dataArray.count == self.total) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
            if (self.tableView.mj_footer.cl_height == 44.0f) {
                self.tableView.mj_footer.cl_height = 138.0f;
                if (bottom == 44.0f || bottom == GK_SAVEAREA_BTM + 44.0f) {
                    self.tableView.mj_insetB = 138.0f;
                }
            }
        }else{
            [self.tableView.mj_footer resetNoMoreData];
            if (self.tableView.mj_footer.cl_height == 138.0f) {
                self.tableView.mj_footer.cl_height = 44.0f;
                if (bottom == 138.0f) {
                    self.tableView.mj_insetB = 44.0f;
                }
            }
        }
        
        self.noDataLb.hidden = self.dataArray.count > 0;
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updateItemStatus" object:nil userInfo:@{@"data":self.postId,@"status":@0}];
        
        [WHToast showMessage:@"删除成功" duration:2 finishHandler:nil];
        
    } failure:^(NSError *error) {
        [WHToast showImage:[UIImage imageNamed:@"toast_tag_error"] message:error.userInfo[@"info"] duration:2 finishHandler:nil];
    }];
}
- (void)reportPostReplyById:(NSNumber *)replyId{
    [MGJRouter openURL:@"local://ddup/report" withUserInfo:@{@"navigationVC":self.navigationController,@"reportId":replyId ,@"reportType":@(0)} completion:nil];
}
- (void)removePostReplyById:(NSNumber *)replyId commentId:(NSNumber *)commentId{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"id"] = replyId;
    param[@"md5"] = [RPAppManager md5StrWithApi:DeleteCommentReply];
    [[RPNetworkExtensionTool sharedTool]requestPOST:kGET_REQUEST_URL(DeleteCommentReply) parames:param success:^(id responseObj) {
        NSInteger index = -1;
        HomePageCommentItemModel *currentModel = nil;
        for (int i = 0; i < self.dataArray.count; i++) {
            HomePageCommentItemModel *model = self.dataArray[i];
            if ([model.id isEqualToNumber:commentId]) {
                index = i;
                currentModel = model;
                break;
            }
        }
        
        if (index != -1) {
            currentModel.replyInCommentVM.replyNum = @0;
            [self.tableView reloadRow:index inSection:0 withRowAnimation:UITableViewRowAnimationAutomatic];
        }
        [WHToast showMessage:@"删除成功" duration:2 finishHandler:nil];
    
    } failure:^(NSError *error) {
        [WHToast showImage:[UIImage imageNamed:@"toast_tag_error"] message:error.userInfo[@"info"] duration:2 finishHandler:nil];
    }];
}

- (void)reportPostCommentById:(NSNumber *)commentId{
    [MGJRouter openURL:@"local://ddup/report" withUserInfo:@{@"navigationVC":self.navigationController,@"reportId":commentId ,@"reportType":@(0)} completion:nil];
}
- (void)showUserInfoByUserId:(NSNumber *)userId{
    
    [MGJRouter openURL:@"local://ddup/homePage/userInfo" withUserInfo:@{@"navigationVC":self.navigationController,@"userId":userId,@"loadType":@(1)} completion:nil];
}
- (void)showMoreReplyMessageByItemModel:(HomePageCommentItemModel *)itemModel{
    if (self.showMoreReplyMessage) {
        self.showMoreReplyMessage(itemModel);
    }
}

- (void)sendPostCommentById:(NSNumber *)commentId{
    if (self.sendReplyComment) {
        self.sendReplyComment(commentId);
    }
}
- (void)doDissOrLikeWithStatus:(BOOL)status commentId:(NSNumber *)commentId{
    if (![RPAppManager isLogin]) {
        [MGJRouter openURL:@"local://ddup/unLogin" withUserInfo:@{@"navigationVC":self.navigationController} completion:nil];
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = [RPAppManager getCustomerId];
    param[@"type"] = @1;
    param[@"isTourist"] = status?@1:@2;
    param[@"evaluateType"] = @(2);
    param[@"postId"] = commentId;
    [[RPNetworkExtensionTool sharedTool]requestPOST:kGET_REQUEST_URL(DoDetailLike) parames:param success:^(id responseObj) {
          
        [MobClick event:@"comment_detail_like"];
    } failure:^(NSError *error) {
        [WHToast showMessage:error.userInfo[@"info"] duration:2 finishHandler:nil];
        __block NSInteger index = -1;
        [self.dataArray enumerateObjectsUsingBlock:^(HomePageCommentItemModel  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj.id isEqualToNumber:commentId]) {
                index = idx;
                *stop = YES;
            }
        }];
        if (index != -1) {
            HomePageCommentItemModel *model = self.dataArray[index];
            NSInteger likeNum = model.likeNum.intValue;
            if (model.like) {
                likeNum--;
              
            }else{
                likeNum++;
            }
            model.likeNum = @(likeNum);
            model.like = !model.like;
            [self.tableView reloadRow:index inSection:0 withRowAnimation:UITableViewRowAnimationNone];
        }
                
    }];
}

- (void)dealloc{
    
}

@end
